package airthmetic.exercise.sort.cmp;


// 冒泡排序 此题部分测试用例回超时
public class _912_排序数组_Bubble3 {

    public int[] sortArray(int[] nums) {
        if (nums == null || nums.length < 2) {
            return nums;
        }
        int n = nums.length;
        for(int i=0; i< n; i++){
            for(int j=0; j<n-i-1; j++){
                if(nums[j] > nums[j+1]){
                    swap(nums, j, j+1);
                }
            }
        }

        return nums;

    }



    public void swap(int[] nums, int left, int right) {
        if (left == right) {
            return;
        }
        nums[left] ^= nums[right];
        nums[right] ^= nums[left];
        nums[left] ^= nums[right];
    }
}
